﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace CoreWeb.Utility.Filter
{
    public class CustomActionFilterAttribute:Attribute,IActionFilter,IFilterMetadata,IOrderedFilter
    {
        public int Order { get; set; }

        public CustomActionFilterAttribute() { }
        /// <summary>
        /// Called before the action executes, after model binding is complete.
        /// </summary>
        /// <param name="context">The <see cref="ActionExecutingContext"/>.</param>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            Console.WriteLine($"this is {typeof(CustomActionFilterAttribute)} OnActionExecuting");
        }

        /// <summary>
        /// Called after the action executes, before the action result.
        /// </summary>
        /// <param name="context">The <see cref="ActionExecutedContext"/>.</param>
        public void OnActionExecuted(ActionExecutedContext context)
        {
            Console.WriteLine($"this is {typeof(CustomActionFilterAttribute)} OnActionExecuted");
        }
    }
    public class CustomResultFilterAttribute : Attribute, IResultFilter, IFilterMetadata, IOrderedFilter
    {
        public int Order { get; set; } 
        public void OnResultExecuting(ResultExecutingContext context)
        {
            Console.WriteLine($"this is {typeof(CustomResultFilterAttribute)} OnResultExecuting");
        }

        public void OnResultExecuted(ResultExecutedContext context)
        {
            Console.WriteLine($"this is {typeof(CustomResultFilterAttribute)} OnResultExecuted");
        }
    }
    public class CustomResourceFilterAttribute : Attribute, IResourceFilter, IFilterMetadata, IOrderedFilter
    {
        public int Order { get; set; } 

        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            Console.WriteLine($"this is {typeof(CustomResourceFilterAttribute)} OnResourceExecuting");
        }

        public void OnResourceExecuted(ResourceExecutedContext context)
        {
            Console.WriteLine($"this is {typeof(CustomResourceFilterAttribute)} OnResourceExecuted");
        }
    }
}
